home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / METAKIT.ZIP / INCLUDE / K4VIEWX.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-09  |  8.3 KB  |  233 lines

  1. //@doc      VIEWX HDR CORE
  2. //@module   VIEWX.H - Auxiliary view declarations |
  3. //  
  4. //  This file contains the declaration of the auxiliary view classes.
  5. //  
  6. //@normal   Copyright <cp> 1996 Meta Four Software. All rights reserved.
  7.  
  8. #ifndef __K4VIEW_H__
  9.     #error This file is included by "k4view.h", it cannot be used standalone
  10. #endif
  11.  
  12. /////////////////////////////////////////////////////////////////////////////
  13. // Declarations in this file
  14.  
  15.     class c4_Sequence;                  // a collection of rows
  16.  
  17.     class c4_Reference;                 // refers to the actual data values
  18.         class c4_IntRef;
  19.         class c4_FloatRef;
  20.         class c4_DoubleRef;
  21.         class c4_StringRef;
  22.         class c4_ViewRef;
  23.  
  24.     class c4_Bytes;                     // not defined here
  25.     class c4_Dependencies;              // not defined here
  26.     class c4_Handler;                   // not defined here
  27.     class c4_Notifier;                  // not defined here
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. /*@class A sequence is an abstract base class for views on ranges of records.
  31.  
  32.     Sequences represent arrays of rows (or indexed collections / tables).
  33.     Insertion and removal of entries is allowed, but can take linear time.
  34.     A reference count is maintained to decide when the object should go away.
  35. */
  36.  
  37. class c4_Sequence
  38. {
  39.     //@cmember Reference count.
  40.     int _refCount;
  41.     //@cmember Pointer to depency list, or null if nothing depends on this.
  42.     c4_Dependencies* _dependencies;
  43.     //@cmember Optimization: cached property index.
  44.     int _lastPropIndex;
  45. protected:
  46.     //@cmember Optimization: cached property id.
  47.     int _lastPropId; // see c4_HandlerSeq::Reset()
  48.  
  49. public: 
  50. //@group General
  51.     //@cmember Abstract constructor.
  52.     c4_Sequence ();
  53.     
  54.     //@cmember Compares the specified row with another one.
  55.     virtual int Compare(int, c4_Cursor) const;
  56.     //@cmember Replaces the contents of a specified row.
  57.     void SetAt(int, c4_Cursor);
  58.     //@cmember Remaps the index to an underlying view.
  59.     virtual int RemapIndex(int, const c4_Sequence*) const;
  60.     
  61.     //@cmember Returns a descriptions of the current data structure.
  62.     c4_String Describe() const;
  63.  
  64. //@group Reference counting
  65.     //@cmember Increments the reference count of this sequence.
  66.     void IncRef();
  67.     //@cmember Decrements the reference count, delete objects when last.
  68.     void DecRef();
  69.     //@cmember Returns the current number of references to this sequence.
  70.     int NumRefs() const;
  71.  
  72. //@group Adding / removing rows
  73.     //@cmember Returns the current number of rows.
  74.     virtual int Size() const = 0;
  75.     //@cmember Changes number of rows, either by inserting or removing them.
  76.     void Resize(int, int =-1);
  77.     
  78.     //@cmember Inserts one or more rows into this sequence.
  79.     virtual void InsertAt(int, c4_Cursor, int =1);
  80.     //@cmember Removes one or more rows from this sequence.
  81.     virtual void RemoveAt(int, int =1);
  82.     //@cmember Move a row to another position.
  83.     virtual void Move(int, int);
  84.  
  85. //@group Properties
  86.     //@cmember Returns the id of the N-th property.
  87.     virtual int NthProperty(int) const;
  88.     //@cmember Finds the index of a property, or creates a new entry.
  89.     int PropIndex(int, bool =false);
  90.     
  91.     //@cmember Returns the number of data handlers in this sequence.
  92.     virtual int NumHandlers() const = 0;
  93.     //@cmember Returns a reference to the N-th handler in this sequence.
  94.     virtual c4_Handler& NthHandler(int) const = 0;
  95.     //@cmember Returns the context of the N-th handler in this sequence.
  96.     virtual const c4_Sequence* HandlerContext(int) const = 0;
  97.     //@cmember Adds the specified data handler to this sequence.
  98.     virtual int AddHandler(c4_Property&, c4_Handler*) = 0;
  99.  
  100. //@group Element access
  101.     //@cmember Retrieves one data item from this sequence.
  102.     virtual bool Get(int, int, c4_Bytes&);
  103.     //@cmember Stores a data item into this sequence.
  104.     virtual void Set(int, int, const c4_Bytes&);
  105.     
  106. //@group Dependency notification
  107.     //@cmember Registers a sequence to receive change notifications.
  108.     void Attach(c4_Sequence* child_);
  109.     //@cmember Unregisters a sequence which received change notifications.
  110.     void Detach(c4_Sequence* child_);
  111.     //@cmember Returns a pointer to the dependencies, or null.
  112.     c4_Dependencies* GetDependencies() const;
  113.  
  114.     //@cmember Called just before a change is made to the sequence.
  115.     virtual c4_Notifier* PreChange(c4_Notifier& nf_);
  116.     //@cmember Called after changes have been made to the sequence.
  117.     virtual void PostChange(c4_Notifier& nf_);
  118.     
  119. protected:
  120.     virtual ~c4_Sequence ();
  121.  
  122. public: //! for c4_Table::Sequence setup
  123.     virtual void SetSize(int size_) = 0;
  124.  
  125. private:
  126.     c4_Sequence (const c4_Sequence&);   // not implemented
  127.     void operator= (const c4_Sequence&); // not implemented
  128. };
  129.  
  130. /////////////////////////////////////////////////////////////////////////////
  131. /*@class A reference is used to get or set typed data, using derived classes.
  132.  
  133. @xref <c c4_IntRef>, <c c4_FloatRef>, <c c4_DoubleRef>,
  134.         <c c4_StringRef>, <c c4_ViewRef>
  135. */
  136.  
  137. class c4_Reference
  138. {
  139.     //@cmember The cursor which points to the data.
  140.     c4_Cursor _cursor;
  141.     //@cmember The property id associated to this reference.
  142.     int _propId;
  143. public: //@access Public members
  144.     //@cmember Constructor.
  145.     c4_Reference (c4_RowRef, int);
  146.  
  147.     //@cmember Assignment of one data item.
  148.     c4_Reference& operator= (const c4_Reference&);
  149.  
  150.     //@cmember Retrieves the value of the referenced data item.
  151.     bool GetData(c4_Bytes&) const;
  152.     //@cmember Stores a value into the referenced data item.
  153.     void SetData(const c4_Bytes&) const;
  154.     
  155.     //@cmember Returns true if the contents of both references is equal.
  156.     friend bool operator== (const c4_Reference&, const c4_Reference&);
  157.     //@cmember Returns true if the contents of both references is not equal.
  158.     friend bool operator!= (const c4_Reference&, const c4_Reference&);
  159.  
  160. private:
  161.     void operator& () const;            // not implemented
  162. };
  163.  
  164. /////////////////////////////////////////////////////////////////////////////
  165.  
  166.     //@class Used to get or set integer values.
  167.     //@base public | <c c4_Reference>
  168. class c4_IntRef : public c4_Reference
  169. {
  170. public: //@access Public members
  171.     //@cmember Constructor.
  172.     c4_IntRef (const c4_Reference&);
  173.     //@cmember Gets the value as long integer.
  174.     operator long () const;
  175.     //@cmember Sets the value to the specified long integer.
  176.     c4_IntRef& operator= (long);
  177. };
  178.  
  179.     //@class Used to get or set floating point values.
  180.     //@base public | <c c4_Reference>
  181. class c4_FloatRef : public c4_Reference
  182. {
  183. public: //@access Public members
  184.     //@cmember Constructor.
  185.     c4_FloatRef (const c4_Reference&);
  186.     //@cmember Gets the value as floating point.
  187.     operator double () const;
  188.     //@cmember Sets the value to the specified floating point.
  189.     c4_FloatRef& operator= (double);
  190. };
  191.  
  192.     //@class Used to get or set double precision values.
  193.     //@base public | <c c4_Reference>
  194. class c4_DoubleRef : public c4_Reference
  195. {
  196. public: //@access Public members
  197.     //@cmember Constructor.
  198.     c4_DoubleRef (const c4_Reference&);
  199.     //@cmember Gets the value as floating point.
  200.     operator double () const;
  201.     //@cmember Sets the value to the specified floating point.
  202.     c4_DoubleRef& operator= (double);
  203. };
  204.  
  205.     //@class Used to get or set string values.
  206.     //@base public | <c c4_Reference>
  207. class c4_StringRef : public c4_Reference
  208. {
  209. public: //@access Public members
  210.     //@cmember Constructor.
  211.     c4_StringRef (const c4_Reference&);
  212.     //@cmember Gets the value as string.
  213.     operator c4_String () const;
  214.     //@cmember Sets the value to the specified string.
  215.     c4_StringRef& operator= (const char*);
  216. };
  217.  
  218.     //@class Used to get or set view values.
  219.     //@base public | <c c4_Reference>
  220. class c4_ViewRef : public c4_Reference
  221. {
  222. public: //@access Public members
  223.     //@cmember Constructor.
  224.     c4_ViewRef (const c4_Reference&);
  225.     //@cmember Gets the value as view.
  226.     operator c4_View () const;
  227.     //@cmember Sets the value to the specified view.
  228.     c4_ViewRef& operator= (const c4_View&);
  229. };
  230.  
  231. /////////////////////////////////////////////////////////////////////////////
  232. // $Id: k4viewx.h,v 1.9 1996/12/08 11:22:41 jcw Exp $
  233.